package com.jinhongone.pattern.behavior.iterator;

import java.util.List;

/**
 * @author jinho
 * @className StudentIteratorImpl
 * @description 具体迭代器角色，提供具体的迭代方法
 * @date 2025/4/17 8:58
 */
public class StudentIteratorImpl implements StudentIterator {
    //元素集合
    private List<Student> students;
    //遍历元素的位置记录
    private int position = 0;

    public StudentIteratorImpl(List<Student> students) {
        this.students = students;
    }

    @Override
    public boolean hasNext() {
        //通过指针位置判断是否有下一个元素
        return position < students.size();
    }

    @Override
    public Student next() {
        //根据指针获取元素，并移动指针。
        return students.get(position++);
    }
}
